/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import Entity.KhoanNo;
import Util.DatabaseHandle;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Dark_Knight
 */
public class KhoanNoImpl implements KhoanNoDAO {

    public boolean add(KhoanNo data) {
        String sql = "{call sp_KHOANNO_add(?,?,?,?,?,?)}";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        try {
            db.setOutParameter(1, java.sql.Types.INTEGER);
            db.setParameter(2, data.getMaKH());
            db.setParameter(3, data.getMaDonHang());
            db.setParameter(4, data.getSoTien());
            db.setParameter(5, data.getNgayBatDau());
            db.setParameter(6, data.getGhiChu());
            
            db.executeStorePro();
            
            data.setMaNo(db.getIntOutValue(1));
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(KhoanNoImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
    }

    public boolean delete(int MaNo) {
        String sql = "{call sp_KHOANNO_delete(?,?,?,?,?,?)}";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        try {
            db.setParameter(1, MaNo);
            db.executeStorePro();
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(KhoanNoImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }            
    }

    public boolean edit(KhoanNo data) {
        String sql = "{call sp_KHOANNO_edit(?,?,?,?,?,?)}";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        try {
            db.setParameter(1, data.getMaNo());
            db.setParameter(2, data.getMaKH());
            db.setParameter(3, data.getMaDonHang());
            db.setParameter(4, data.getSoTien());
            db.setParameter(5, data.getNgayBatDau());
            db.setParameter(6, data.getGhiChu());
            
            db.executeStorePro();            
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(KhoanNoImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
    }
    
}
